package vip.liux.contracts.models.files;

import org.springframework.util.Assert;

public class FileNameValidator {
    public static boolean isValidName(String name) {
        if (name == null || name.isBlank()) {
            return false;
        }

        // con is not valid folder/file name for Windows
        return !(name.contains("con") || name.contains("CON") || name.contains("Con") || name.contains("cOn") || name.contains("coN") || name.contains("COn") || name.contains("cON") || name.contains("CoN"));
    }

    public static String checkFileName(String name) {
        Assert.hasText(name, "File name cannot be null or empty");

        if (!isValidName(name)) {
            throw new IllegalArgumentException("Invalid file name: " + name);
        }
        return name;
    }

    public static String checkDirectoryName(String name) {
        Assert.hasText(name, "Directory name cannot be null or empty");

        if (!isValidName(name)) {
            throw new IllegalArgumentException("Invalid directory name: " + name);
        }
        return name;
    }
}
